using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccessLayer
{
    public class DAO_Question_Info
    {
        public static bool Insert(Object tmp)
        {
            QUESTION_INFO obj = (QUESTION_INFO)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@QUESTION_ID", obj.QUESTION_ID));            
            _list.Add(new SqlParameter("@QUESTION_INFO_PROP", obj.QUESTION_INFO_PROP));
            _list.Add(new SqlParameter("@QUESTION_INFO_VALUE", obj.QUESTION_INFO_VALUE));
            
            int n = clsDataAccessHelper.ExecNonQuery("sp_question_info_insert", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static List<QUESTION_INFO> Select(int questionID)
        {
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@QUESTION_ID", questionID));

            DataTable table = clsDataAccessHelper.ExecuteQuery("sp_select_question_info", _list);
            if (table != null)
            {
                List<QUESTION_INFO> questionList = new List<QUESTION_INFO>();
                foreach (DataRow row in table.Rows)
                {
                    QUESTION_INFO info = new QUESTION_INFO();
                    info.QUESTION_ID = questionID;
                    info.QUESTION_INFO_ID = decimal.Parse(row["QUESTION_INFO_ID"].ToString());
                    info.QUESTION_INFO_PROP = row["QUESTION_INFO_PROP"].ToString();
                    info.QUESTION_INFO_VALUE = row["QUESTION_INFO_VALUE"].ToString();

                    questionList.Add(info);
                }
                return questionList;
            }
            return null;
        }

        public static bool Update(Object tmp)
        {
            QUESTION_INFO obj = (QUESTION_INFO)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@QUESTION_ID", obj.QUESTION_ID));
            _list.Add(new SqlParameter("@QUESTION_INFO_ID", obj.QUESTION_INFO_ID));
            _list.Add(new SqlParameter("@QUESTION_INFO_PROP", obj.QUESTION_INFO_PROP));
            _list.Add(new SqlParameter("@QUESTION_INFO_VALUE", obj.QUESTION_INFO_VALUE));

            int n = clsDataAccessHelper.ExecNonQuery("sp_question_info_update", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static bool Delete(Object tmp)
        {
            QUESTION_INFO obj = (QUESTION_INFO)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            //_list.Add(new SqlParameter("@QUESTION_ID", obj.QUESTION_ID));
            _list.Add(new SqlParameter("@QUESTION_INFO_ID", obj.QUESTION_INFO_ID));
            //_list.Add(new SqlParameter("@QUESTION_INFO_PROP", obj.QUESTION_INFO_PROP));
            //_list.Add(new SqlParameter("@QUESTION_INFO_VALUE", obj.QUESTION_INFO_VALUE));

            int n = clsDataAccessHelper.ExecNonQuery("sp_question_info_delete", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static List<QUESTION_INFO> LoadAll()
        {
            List<QUESTION_INFO> _list = new List<QUESTION_INFO>();
            //call stored getlist here
            return _list;
        }
    }
}
